package data_structure;

import java.util.ArrayList;
import java.util.List;

public class leetcode_0104 {
    public int maxDepth(TreeNode root) {
        int deep=0;
        if(root==null) return 0;
        List<TreeNode> stack=new ArrayList<>();
        int current=0;
        int count=1;
        stack.add(root);
        while(count!=0){
            deep++;
            for(int i=0;i<count;++i){
                TreeNode node=stack.remove(0);
                if(node.left!=null) {
                    stack.add(node.left);
                    current++;
                }
                if(node.right!=null){
                    stack.add(node.right);
                    current++;
                }

            }
            count=current;
            current=0;
        }
        return deep;
    }
}
